<?php include("include.php");?>
<?php 

$jobid = $_POST['jobid'];
$tcount = $_POST['thresholdcount'];
$job = job::getJobById($jobid);
//Verify that a ressource has been selected abd there isnt an error
if((!empty($_FILES["uploaded_file"])) && ($_FILES['uploaded_file']['error'] == 0)) {
	//get the filename and the  extension
	 $filename = basename($_FILES['uploaded_file']['name']);
 	 $ext = substr($filename, strrpos($filename, '.') + 1);
  if ($_FILES["uploaded_file"]["size"] < quark::RESSOURCE_MAX_SIZE) {
   	 //Determine the path to which we want to save this file
	  $newname = dirname(__FILE__)."\\".quark::getFolderPath($currentUser->getId(),$job->getId())."\\".$filename;
	   if (!file_exists($newname)) {
		if ((move_uploaded_file($_FILES['uploaded_file']['tmp_name'],$newname))) {
				   //creating the quark
				   quark::createquark($job->getId(),$filename,$tcount,0,0);	   
				} else {
				   setError("","Ressource cannot be uploaded");
				}
	   }else{
		   setError("","Ressource already exits");
	   }
  }else{
   setError("","Ressource is too big");
  		//Ressource is too big
  }
}else{
   setError("","No Ressource specified");
	//No ressource specified
}
?>
<meta http-equiv="REFRESH" content="0;url=jobQuarks.php?jid=<?php echo $jobid;?>">
<?php include("includes/footer.php");?>